package com.glela.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.glela.platform.constant.ErrorEnum;
import com.glela.platform.model.User;
import com.glela.platform.model.response.ResponseBaseModel;
import com.glela.platform.service.UserFansService;
import com.glela.platform.service.UserService;
import com.glela.platform.vo.UserFansVo;

@Controller
@RequestMapping(value = "/userFans")
public class UserFansController {

	private static Logger logger = LoggerFactory.getLogger(UserController.class);

	@Autowired
	private UserFansService userFansService;
	@Autowired
	private UserService userService;

	/**
	 * 加粉&掉粉
	 * 
	 * @param requestUserSet
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/addUserAddress", method = RequestMethod.POST, consumes = "application/json")
	public ResponseEntity<?> addUserAddress(@RequestBody UserFansVo userFansVo) {
		try {
			User user = userService.getUser(userFansVo.getUserId());
			if (user == null) {
				return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C20113), HttpStatus.OK);
			}
			User talentUser = userService.getUser(userFansVo.getTalentId());
			if (talentUser == null) {
				return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C20113), HttpStatus.OK);
			}
			if (userFansVo.getType() != 0 && userFansVo.getType() != 1) {
				return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C20133), HttpStatus.OK);
			}
			int a = userFansService.attentionAndAbolish(userFansVo.getUserId(), userFansVo.getTalentId(),
					userFansVo.getType());
			if (a == 0) {
				return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C20134), HttpStatus.OK);
			}
			if (a == 1) {
				return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C20135), HttpStatus.OK);
			}
			// if (a == 2) {
			// return new ResponseEntity<>(new
			// ResponseBaseModel(ErrorEnum.C20136), HttpStatus.OK);
			// }
			// if (a == 3) {
			// return new ResponseEntity<>(new
			// ResponseBaseModel(ErrorEnum.C20137), HttpStatus.OK);
			// }
			return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C10000), HttpStatus.OK);
		} catch (Exception e) {
			logger.error("添加取消关注异常:", e);
			return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C20000), HttpStatus.OK);
		}
	}
}
